/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.nacos.naming.cluster.transport;

import com.alibaba.nacos.naming.consistency.Datum;
import com.alibaba.nacos.naming.pojo.Record;

import java.util.Map;

/**
 * 序列化.
 *
 * @author nkorange
 * @since 1.0.0
 */
public interface Serializer {

    /**
     * 使用某种序列化协议序列化数据.
     *
     * @param data 要序列化的数据
     * @param <T>  数据类型
     * @return 字节数组
     */
    <T> byte[] serialize(T data);

    /**
     * 反序列化数据为指定类型.
     *
     * @param data  反序列化的数据
     * @param clazz 目标类型
     * @param <T>   目标类型
     * @return 反序列化后的对象
     */
    <T> T deserialize(byte[] data, Class<T> clazz);

    /**
     * 反序列化数据为指定类型.
     *
     * @param <T>   目标类型
     * @param data  反序列化的数据
     * @param clazz 目标类型
     * @return 反序列化后的数据集合
     */
    <T extends Record> Map<String, Datum<T>> deserializeMap(byte[] data, Class<T> clazz);
}
